<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@page contentType="text/html; charset=UTF-8" import="java.util.*, user.*"%>
<%@ page import="java.sql.*"%> 

<%  
	if (
	String username = session.getAttribute("username").toString();  
	String CusID = LoginValidation.getUserId(username);
	String address = request.getParameter("clientCheckout_streetField");
	String name = request.getParameter("clientCheckout_receiverName");
	String phone = request.getParameter("clientCheckout_cell");	
	
	DBConnector db = DBConnector.getDBConnector();
	String AllOrderForms = "select form_ID from order_form where cus_ID = " + CusID + " and form_state = 'not cooked yet'";
	db.prepareStatement(AllOrderForms);
	ResultSet AllOrderFormsResult = db.queryPstmt();
	
	if (AllOrderFormsResult != null)
	{
		AllOrderFormsResult.next();	
		String FormID = AllOrderFormsResult.getString(1);
		String updateOrderForm = "update order_form set receiver_name = '" + name + 
								"', receiver_phone = '" + phone + 
								"', receiver_add = '" + address + 
								"', form_state = 'cooking' where form_ID = " + FormID;
								
		db.prepareStatement(updateOrderForm);
		db.updatePstmt();
	}
	else
	{
		System.out.println("There are currently no selected food");
		String resultURL = "<script type =\"text/javascript\"> window.location.href = '../index.jsp'</script>";
		out.println(resultURL);
	}
%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>"> 
    <title>My JSP 'DisplayInvoicePage.jsp' starting page</title>
  </head>
  
  <body>
    <br>
    <th><center>Thank you very much for your order.</center></th>
    <th><center>Customer Information</center></th>
    
    <table width = 50% align = center border = 1>
	<tr bgcolor="#666666\">
	<th width="100" bgcolor="#CCCCCC" scope="col">Name</th>
	<th width="100" bgcolor="#CCCCCC" scope="col">Phone</th>
	<th width="100" bgcolor="#CCCCCC" scope="col">Address</th>
	</tr>
	<tr><td><%=name %></td><td><%=phone %></td><td><%=address %></td></tr>
	</table>

    <br><br>
    <th><center>Food in Order</center></th>
    <%= DisplayCustomerInvoice.GetContainInfo(username)%><br>
    <form action = "./index.jsp" method = "get" />
    <center><input type= "submit" value = "Back to Index" name = "submit" /> </center>
	</form>
  </body>
</html>
